﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using KBC_Quiz_Show.DBConnect;
using KBC_Quiz_Show.Object;
using KBC_Quiz_Show.Presentation;
using System.Collections;


namespace KBC_Quiz_Show.Bussiness
{
    class QuestionController
    {
        DataSet ds;
        ArrayList list = new ArrayList();
        ArrayList list1 = new ArrayList();
        SqlCommand cmd;
        SqlDataAdapter da;
        SqlConnection conn;
        //SqlDataReader reader, reader1;
        Question question = new Question();
        Utils database = new Utils();
        public DataSet LoadQuestion()
        {
            conn = database.getConnection();
            conn.Open();
            ds = new DataSet();
            cmd = new SqlCommand("getAllQuestion", conn);
            da = new SqlDataAdapter(cmd);
            da.Fill(ds, "Question");
            return ds;
        }
        public void InsertQuestion(string quesContent, string ans1, string ans2, string ans3, string ans4, int level, string anstrue)
        {
            conn = database.getConnection();
            conn.Open();
            cmd = new SqlCommand("insertQuestion", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            // cmd.Parameters.Add("@ques_id", SqlDbType.Int).Value = quesID;
            cmd.Parameters.Add("@ques_content", SqlDbType.VarChar).Value = quesContent;
            cmd.Parameters.Add("@ans1", SqlDbType.VarChar).Value = ans1;
            cmd.Parameters.Add("@ans2", SqlDbType.VarChar).Value = ans2;
            cmd.Parameters.Add("@ans3", SqlDbType.VarChar).Value = ans3;
            cmd.Parameters.Add("@ans4", SqlDbType.VarChar).Value = ans4;
            cmd.Parameters.Add("@ques_level", SqlDbType.Int).Value = level;
            cmd.Parameters.Add("@anstrue", SqlDbType.VarChar).Value = anstrue;
            int i = cmd.ExecuteNonQuery();
        }
        public void UpdateQuestion(int quesID, string quesContent, string ans1, string ans2, string ans3, string ans4, int level, string anstrue)
        {
            conn = database.getConnection();
            conn.Open();
            cmd = new SqlCommand("updateQuestion", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@ques_id", SqlDbType.Int).Value = quesID;
            cmd.Parameters.Add("@ques_content", SqlDbType.VarChar).Value = quesContent;
            cmd.Parameters.Add("@ans1", SqlDbType.VarChar).Value = ans1;
            cmd.Parameters.Add("@ans2", SqlDbType.VarChar).Value = ans2;
            cmd.Parameters.Add("@ans3", SqlDbType.VarChar).Value = ans3;
            cmd.Parameters.Add("@ans4", SqlDbType.VarChar).Value = ans4;
            cmd.Parameters.Add("@ques_level", SqlDbType.Int).Value = level;
            cmd.Parameters.Add("@anstrue", SqlDbType.VarChar).Value = anstrue;
            int i = cmd.ExecuteNonQuery();
        }
        public void DelQuestion(int quesID)
        {
            conn = database.getConnection();
            conn.Open();
            cmd = new SqlCommand("deleteQuestion", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@ques_id", SqlDbType.VarChar).Value = quesID;
            int i = cmd.ExecuteNonQuery();

        }
        public void GetQuestion_quesID(int quesID)
        {

            conn = database.getConnection();
            conn.Open();
            cmd = new SqlCommand("getQuestion_quesID", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@ques_id", SqlDbType.VarChar).Value = quesID;
            da.Fill(ds);
            da.Dispose();
        }
        public DataSet SearchQuestion(int quesID)
        {
            conn = database.getConnection();
            conn.Open();
            ds = new DataSet();
            cmd = new SqlCommand("getAllQuestion_quesID", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@ques_id", SqlDbType.Int).Value = quesID;
            da = new SqlDataAdapter(cmd);
            da.Fill(ds, "Question");
            return ds;
        }

    }
}
